package com.xiaocikuai.smallchunks.service.Advertise.impl;

import com.xiaocikuai.smallchunks.entity.Advertise.ImgUni;
import com.xiaocikuai.smallchunks.entity.User.Duser;
import com.xiaocikuai.smallchunks.file.PutObject004;
import com.xiaocikuai.smallchunks.mapper.Advertise.ImgUniMapper;
import com.xiaocikuai.smallchunks.service.Advertise.IImgUniService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author1
 * @since 2024-07-27
 */
@Service
public class ImgUniServiceImpl extends ServiceImpl<ImgUniMapper, ImgUni> implements IImgUniService {

    @Autowired
    private PutObject004 putObject004;
    public List<ImgUni> selectByType(int type){
        return lambdaQuery().eq(ImgUni::getType,type).orderByAsc(ImgUni::getTag).select().list();
    }

    public boolean updateList(ImgUni imgUni,MultipartFile file){
        if (file != null)
            imgUni.setImg(addImg(file));
        return updateById(imgUni);
    }


    public String addImg(MultipartFile file){
        return putObject004.uploadFile(file, "ad");
    }




}


